package com.peng.leetcode.dynamic;

/**
 * Rob
 * <p>
 * 198. 打家劫舍
 *
 * @author: lupeng6
 * @create: 2021/2/18 17:11
 */
public class Rob {

    public static void main(String[] args) {
        int[] nums = {1, 2, 3, 1};
        System.out.println(new Rob().rob(nums));
    }

    public int rob(int[] nums) {
        if (nums == null || nums.length == 0) {
            return 0;
        }
        int size = nums.length;
        int[] dp = new int[size + 1];
        dp[0] = 0;
        dp[1] = nums[0];
        for (int i = 2; i <= size; i++) {
            dp[i] = Math.max(dp[i - 1], nums[i - 1] + dp[i - 2]);
        }
        return dp[size];
    }
}
